package com.wenc.psi.rvAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wenc.psi.R;
import com.wenc.psi.bean.SaleBean;
import com.wenc.psi.pojo.Sale;

import java.util.List;

public class SaleOrderAdapter extends RecyclerView.Adapter<SaleOrderAdapter.SaleOrderViewHolder>{

    private List<Sale> saleList;

    public void setSaleList(List<Sale> saleList) {
        this.saleList = saleList;
    }

    @NonNull
    @Override
    public SaleOrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        View itemView = layoutInflater.inflate(R.layout.cell_sale_order, parent, false);
        return new SaleOrderViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull SaleOrderViewHolder holder, int position) {
        Sale sale = saleList.get(position);
        holder.tv_id.setText(sale.getId());
        holder.tv_date.setText(String.valueOf(sale.getDate()));
        holder.tv_time.setText(String.valueOf(sale.getTime()));
    }

    @Override
    public int getItemCount() {
        if (saleList != null) return  saleList.size();
        return 0;
    }

    class SaleOrderViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_id, tv_date, tv_time;
        public SaleOrderViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_id = itemView.findViewById(R.id.sale_order_id);
            tv_date = itemView.findViewById(R.id.sale_order_date);
            tv_time = itemView.findViewById(R.id.sale_order_time);
        }
    }
}
